import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:tianpu_edu/Classes/libs/tool_api_url.dart';
import 'package:tianpu_edu/Classes/libs/tool_color_utils.dart';
import 'package:tianpu_edu/Classes/libs/tool_text_utils.dart';

class LoginView extends StatefulWidget {
  @override
  _LoginViewState createState() => _LoginViewState();
}

class _LoginViewState extends State<LoginView> {

  TextEditingController _textName = TextEditingController();
  TextEditingController _textPassword = TextEditingController();
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [

          Container(padding: EdgeInsets.only(top: 12,left: 12),
              child: Text('账号密码登录',style: textStyle(fontSize: 28),)),
          SizedBox(height: 20,),
          Container(padding: EdgeInsets.only(left: 20,right: 20),
              child: TextField(decoration: InputDecoration(labelText: '请输入您的账号'),
                controller: _textName,
              )),
          Container(padding: EdgeInsets.only(left: 20,right: 20),
              child: TextField(decoration: InputDecoration(labelText: '请输入您的密码'),
                controller: _textPassword,obscureText: true,)),//密码
          Container(padding: EdgeInsets.only(left: 10,right: 20),
            child: Row(
              children: [
                IconButton(icon: Icon(Icons.radio_button_off), onPressed: (){}),
                Text('注册/登录即代表同意《天普用户注册协议》《隐私条款》',
                  style: textStyle(fontSize: 13,color: Color(0xFF999999)),)
              ],
            ),
          ),
          SizedBox(height: 40,),
          Container(
            padding: EdgeInsets.only(left: 20,right: 20),
            width: screenSizeW(context),
            height: 44,
            child: FlatButton(
              child: Text('登录',style: TextStyle(color: Colors.white),), onPressed: (){
               if(_textPassword.text.length <= 0 || _textName.text.length <= 0){
                 EasyLoading.showToast('账号密码不能为空，请检查');
                 return;
               }
                _getLogin(_textName.text,_textPassword.text);
            },
              color: mainColor,//按钮颜色
              shape: RoundedRectangleBorder(//圆角设置
                borderRadius: BorderRadius.all(Radius.circular(22)),
              ),
            ),
          ),
          Container(
            padding: EdgeInsets.only(left: 10,right: 10),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                TextButton(onPressed: (){}, child: Text('手机注册',style: textStyle14(color: textColor),)),
                TextButton(onPressed: (){}, child: Text('忘记密码？',style: textStyle14(color: mainColor),)),
              ],
            ),
          )
        ],
      ),
    );
  }

  Future<void> _getLogin(String userName, String password) async {

    ApiUrl.getLogin(null, userName, password, (success) {

      EasyLoading.showToast(success['data']);
    }, (error) {

    });
  }

}
